package com.longtxt.powerband.core

import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.BluetoothGattDescriptor
import com.band.smartband.core.ble.GattStatus
import com.band.smartband.core.ble.HciStatus
import com.band.smartband.core.ble.PhyType

interface BlePeripheralCallback {
    /**
     * Trying to connect to [BlePeripheral]
     *
     * @param peripheral [BlePeripheral] the peripheral.
     */
    fun connecting(peripheral: BlePeripheral)

    /**
     * [BlePeripheral] has successfully connected.
     *
     * @param peripheral [BlePeripheral] that connected.
     */
    fun connected(peripheral: BlePeripheral)

    /**
     * Connecting with [BlePeripheral] has failed.
     *
     * @param peripheral [BlePeripheral] of which connect failed.
     */
    fun connectFailed(peripheral: BlePeripheral, status: HciStatus)

    /**
     * Trying to disconnect to [BlePeripheral]
     *
     * @param peripheral [BlePeripheral] the peripheral.
     */
    fun disconnecting(peripheral: BlePeripheral)

    /**
     * [BlePeripheral] has disconnected.
     *
     * @param peripheral [BlePeripheral] that disconnected.
     */
    fun disconnected(peripheral: BlePeripheral, status: HciStatus)

    /**
     * Callback invoked when the notification state of a characteristic has changed.
     *
     * Use [BlePeripheral.isNotifying] to get the current notification state of the characteristic
     *
     * @param peripheral the peripheral
     * @param characteristic the characteristic for which the notification state changed
     * @param status GATT status code
     */
     fun onNotificationStateUpdate(peripheral: BlePeripheral, characteristic: BluetoothGattCharacteristic, status: GattStatus) {}

    /**
     * Callback invoked as the result of a characteristic read operation or notification/indication
     *
     * @param peripheral the peripheral
     * @param value the new value received
     * @param characteristic the characteristic for which the new value was received
     * @param status GATT status code
     */
     fun onCharacteristicUpdate(peripheral: BlePeripheral, value: ByteArray, characteristic: BluetoothGattCharacteristic, status: GattStatus) {}

    /**
     * Callback invoked as the result of a descriptor read operation
     *
     * @param peripheral the peripheral
     * @param value the read value
     * @param descriptor the descriptor that was read
     * @param status GATT status code
     */
     fun onDescriptorRead(peripheral: BlePeripheral, value: ByteArray, descriptor: BluetoothGattDescriptor, status: GattStatus) {}

    /**
     * Callback invoked as the result of a read RSSI operation
     *
     * @param peripheral the peripheral
     * @param rssi the RSSI value
     * @param status GATT status code
     */
     fun onReadRemoteRssi(peripheral: BlePeripheral, rssi: Int, status: GattStatus) {}

    /**
     * Callback invoked as the result of a MTU request operation
     *
     * @param peripheral the peripheral
     * @param mtu the new MTU
     * @param status GATT status code
     */
     fun onMtuChanged(peripheral: BlePeripheral, mtu: Int, status: GattStatus) {}

    /**
     * Callback invoke as result of readPhy or setPhy operation
     *
     * @param peripheral the peripheral
     * @param txPhy the transmitter PHY in use.
     * @param rxPhy the receiver PHY in use
     * @param status GATT status code
     */
     fun onPhyUpdate(peripheral: BlePeripheral, txPhy: PhyType, rxPhy: PhyType, status: GattStatus) {}

    /**
     * Callback invoked when the connection parameters are updated.
     *
     * This can happen as a result of requestConnectionPriority() or when the stack/peripheral decides to change the connection parameters.
     * This callback is only called for Android 8 (Oreo) or newer.
     *
     * @param peripheral the peripheral
     * @param interval Connection interval used on this connection, 1.25ms unit.
     * Valid range is from 6 (7.5ms) to 3200 (4000ms).
     * @param latency  Slave latency for the connection in number of connection events.
     * Valid range is from 0 to 499.
     * @param timeout  Supervision timeout for this connection, in 10ms unit.
     * Valid range is from 10 (0.1s) to 3200 (32s).
     * @param status GATT status code
     */
     fun onConnectionUpdated(peripheral: BlePeripheral, interval: Int, latency: Int, timeout: Int, status: GattStatus) {}

     fun onReceiveResponse(jsonObject: ByteArray) {}

    fun onReceiveJLResponse(device: BluetoothDevice,rawData: ByteArray) {}

    fun onConnectStatus(device: BluetoothDevice, status: Int)

    fun onJLServiceFound()
    

}